#include "WheelSpinSensor.h"

WheelSpinSensor::~WheelSpinSensor()
{
	if (mFile.is_open()) {
		mFile.close();
	}
}

size_t WheelSpinSensor::GetRevolutions()
{
	if (!mFile.is_open()) {
		mFile = std::ifstream(mFilename);

		if (!mFile.good()) {
			throw std::exception("error when opening the wheelspinsensor's file.");
		}
	}

	size_t revolutions = 0;

	if (mFile.good()) {
		mFile >> revolutions;
	}

	return revolutions;
}
